package org.tobaccomain.utils;



import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private JwtUtils() {
    }

    private static final String key = "tobacco";

    //jwt令牌生成
    public static String generateJwt(Map<String,Object> claims){
        String jwt = Jwts.builder().signWith(SignatureAlgorithm.HS256, key)
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis() + 5 * 3600 * 1000))
                .compact();
        return jwt;
    }

    //jwt令牌解析
    public static Claims parseJwt (String jwt){
        return Jwts.parser().setSigningKey(key).parseClaimsJws(jwt).getBody();
    }
}
